package com.work.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.util.Properties;

//连接池
public class DruidManger {
    //创建管理连接池对象
    private static DataSource dataSource = null;

    static {
        Properties pro =  new Properties();
        try {
            //这里用相对路径报错呜呜，只能用绝对路径
            pro.load(new FileInputStream("C:\\Users\\星星在唱歌\\Desktop\\学习\\LIU\\U2-day02\\src\\com\\work\\druid.properties"));
            //创建druid的工厂类
            dataSource = DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //获取链接池对象
    public static DataSource getDataSource(){
        return dataSource;
    }

    //测试
    public static void main(String[] args) {
        DataSource dataSource =  DruidManger.getDataSource();
        System.out.println(dataSource);
    }
}
